package main.service;

import java.util.*;
import java.math.BigDecimal;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import main.model.*;
import main.dao.*;
import main.vo.*;

@Service
public class TencentMailUserService {


//系统生成代码,请不要修改或删除 <actionStart:MailData>
public List<MailData> MailData(String user,String password) throws Exception {
	//请添加你的业务代码
	input(user, password);

        // 获取邮箱的 token 后，获取邮件未读
        TokenBean tokenBean = HttpUtil.getTokenBean(HttpUtil.MAIL);
        HttpUtil.getMailCountBean(tokenBean.access_token);

        // 获取登录的 token 后，单点登录
        TokenBean tokenBeanLogin = HttpUtil.getTokenBean(HttpUtil.LOGIN);
        HttpUtil.getLoginUrl(tokenBeanLogin.access_token);

        // 获取登录的 token 后，单点登录
        TokenBean tokenBeanLog = HttpUtil.getTokenBean(HttpUtil.LOG);
        HttpUtil.getLogOperation(tokenBeanLog.access_token);
        HttpUtil.getLoginLog(tokenBeanLog.access_token);

        List<EnterpriseMailBean> list = new ArrayList<>();
        try {
            list = EmailUtils.readEmailPop();
        } catch (Exception e) {
            e.printStackTrace();
        }
        List<MailData> maildatas = new ArrayList<>();

        list.sort(((o1, o2) -> o2.date.compareTo(o1.date)));
        list.forEach(i->{
            MailData maildata = new MailData();
            maildata.setSubject(i.subject);
            maildata.setSender(i.sender);
            maildata.setReceiver(i.receiveAddress);
            maildata.setSendDate(i.sentDate);
            maildata.setSize(i.size);
            maildata.setPriority(i.priority);
            maildatas.add(maildata);
        });
        return maildatas;
}
//系统生成代码,请不要修改或删除 <actionEnd:MailData>

private void input(String user, String password) {
	// TODO Auto-generated method stub
	
}


}